﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QLKS
{
    public partial class FrmCheckIn : Form
    {
        int ngay = 0, thang = 0, nam = 0;
        string maphong = null;
        public string MaNV { get; set; }
        public int MaKH { get; set; }

        public FrmCheckIn()
        {
            InitializeComponent();
        }
        public FrmCheckIn(int ngay, int thang, int nam, string maphong)
        {
            InitializeComponent();
            this.ngay = ngay;
            this.thang = thang;
            this.nam = nam;
            this.maphong = maphong;
        }

        private void btn_Close_Click(object sender, EventArgs e)
        {
            this.CloseForm();
        }

        public void NextTab(string maNV, int maKH)
        {
            this.MaNV = maNV;
            this.MaKH = maKH;
            if (tabControlCheckin.SelectedIndex < tabControlCheckin.TabPages.Count)
            {
                tabControlCheckin.SelectedIndex = tabControlCheckin.SelectedIndex + 1;
                tabControlCheckin.SelectedTab = tabControlCheckin.TabPages[tabControlCheckin.SelectedIndex];
            }
            else
                tabControlCheckin.SelectedIndex = tabControlCheckin.TabPages.Count - 1;
        }

        public void PreviousTab()
        {
            if (tabControlCheckin.SelectedIndex > 0)
            {
                tabControlCheckin.SelectedIndex = tabControlCheckin.SelectedIndex - 1;
            }
            else
                tabControlCheckin.SelectedIndex = 0;

        }


        private void FrmCheckIn_Load(object sender, EventArgs e)
        {
            try
            {
                if (tabControlCheckin.SelectedIndex == 0)
                 {
                     frmCheckInchild1 frm1 = new frmCheckInchild1 { TopLevel = false, Parent = tabControlCheckin.TabPages[tabControlCheckin.SelectedIndex], Dock = DockStyle.Fill, FormBorderStyle = FormBorderStyle.None };
                     frm1.Show();
                     tabControlCheckin.SelectedTab = tabControlCheckin.TabPages[tabControlCheckin.SelectedIndex];
                 }
            }
            catch (Exception)
            {
                
                throw;
            }
        }

        private void tabControlCheckin_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                    if (tabControlCheckin.SelectedIndex == 0)
                    {
                        frmCheckInchild1 frm1 = new frmCheckInchild1 { TopLevel = false, Parent = tabControlCheckin.TabPages[tabControlCheckin.SelectedIndex], Dock = DockStyle.Fill, FormBorderStyle = FormBorderStyle.None };
                        frm1.Show();
                        tabControlCheckin.SelectedTab = tabControlCheckin.TabPages[tabControlCheckin.SelectedIndex];
                    }
                else if (tabControlCheckin.SelectedIndex == 1 && ngay==0 && thang == 0 && nam == 0)
                {
                    frmCheckInChild2 frm2 = new frmCheckInChild2(MaNV, MaKH, maphong) { TopLevel = false, Parent = tabControlCheckin.TabPages[tabControlCheckin.SelectedIndex], Dock = DockStyle.Fill, FormBorderStyle = FormBorderStyle.None };
                    frm2.Show();
                    tabControlCheckin.SelectedTab = tabControlCheckin.TabPages[tabControlCheckin.SelectedIndex];
                }
                    else if (tabControlCheckin.SelectedIndex == 1 && ngay != 0 && thang != 0 && nam != 0)
                    {
                        frmCheckInChild2 frm2 = new frmCheckInChild2(ngay,thang,nam,maphong,MaNV,MaKH, maphong) { TopLevel = false, Parent = tabControlCheckin.TabPages[tabControlCheckin.SelectedIndex], Dock = DockStyle.Fill, FormBorderStyle = FormBorderStyle.None };
                        frm2.Show();
                        tabControlCheckin.SelectedTab = tabControlCheckin.TabPages[tabControlCheckin.SelectedIndex];
                    }
            }
            catch (Exception x)
            {
                MessageBox.Show(string.Format("Lỗi: {0}", x.Message), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void tabControlCheckin_MouseClick(object sender, MouseEventArgs e)
        {

            if (tabControlCheckin.SelectedIndex == 1)
            {

                tabControlCheckin.SelectedIndex = 0;
                MessageBox.Show("Không được chuyển mục", "Cảnh báo");
            }
            else
            {
                tabControlCheckin.SelectedIndex = 1;
                MessageBox.Show("Không được chuyển mục", "Cảnh báo");
            }

        }
        public void CloseForm()
        {
            this.Close();
        }
        public void CallForm()
        {
            foreach (Form f in MdiChildren)
            {
                if (f is FrmInfoCustomer)
                {
                    f.Activate();
                    return;
                }
            }
            FrmInfoCustomer obj = new FrmInfoCustomer();
            obj.MdiParent = (Frm_Main)MdiParent;
            obj.Show();
            this.Close();
        }

    }
}
